<template>
  <view class="lists">
    <!--    <scroll-view
      :scroll-top="scrollTop"
      :scroll-with-animation="true"
      scroll-y="true"
      class="scroll-Y scroll"
      id="view1"
    > -->
    <!-- <BaseChart v-if="type === 'height'" :empi="userInfo.empi" :chartInfo="heightInfo" id="height" /> -->
    <BaseChart
      v-if="type === 'BMI'"
      :empi="userInfo.empi"
      :chartInfo="weightInfo"
      id="weight"
      ref="baseChartRef"
    />
    <!-- <BaseChart v-else-if="type === 'bmi'" :empi="userInfo.empi" :chartInfo="bmiInfo" id="bmi" /> -->
    <BaseChart
      v-else-if="type === 'whr'"
      :empi="userInfo.empi"
      :chartInfo="whrInfo"
      id="whr"
      ref="baseChartRef"
    />
    <BloodInfo
      v-else-if="type === 'blood_pressure'"
      :empi="userInfo.empi"
      :type="type"
      id="sbp"
      ref="bloodChartRef"
    />
    <BaseChart
      v-else-if="type === 'heart_rate'"
      :empi="userInfo.empi"
      :chartInfo="heartInfo"
      id="heart_rate"
      ref="baseChartRef"
    />
    <BloodSugarInfo
      v-else-if="type === 'blood_sugar'"
      :empi="userInfo.empi"
      :type="type"
      id="fbg"
      ref="bloodSugarChartRef"
    />
    <BaseChart
      v-else-if="type === 'blood_oxygen'"
      :empi="userInfo.empi"
      :chartInfo="oxygenInfo"
      id="spo2"
      ref="baseChartRef"
    />
    <NewBaseInfo
      v-else-if="type === 'blood_ketone'"
      :empi="userInfo.empi"
      :chartInfo="ketoneInfo"
      id="blood_ketone"
      ref="newBaseChartRef"
    />
    <NewBaseInfo
      v-else-if="type === 'uric_acid'"
      :empi="userInfo.empi"
      :chartInfo="uricAcidInfo"
      id="uric_acid"
      ref="newBaseChartRef"
    />
    <SleepBaseInfo
      v-else-if="type === 'sleep'"
      :empi="userInfo.empi"
      :chartInfo="sleepInfo"
      id="sleep"
      chartType="column"
      ref="sleepChartRef"
    />
    <NewBaseInfo
      v-else-if="type === 'water'"
      :empi="userInfo.empi"
      :chartInfo="waterInfo"
      id="water"
      ref="newBaseChartRef"
    />
    <NewBaseInfo
      v-else-if="type === 'blood_fat'"
      :empi="userInfo.empi"
      :chartInfo="bloodFatInfo"
      id="blood_fat"
      ref="newBaseChartRef"
    />
    <NewBaseInfo
      v-else-if="type === 'liver_function'"
      :empi="userInfo.empi"
      :chartInfo="liverFunctionInfo"
      id="liver_function"
      ref="newBaseChartRef"
    />
    <BaseChart
      v-else-if="type === 'defecate'"
      :empi="userInfo.empi"
      :chartInfo="defecateInfo"
      id="defecate"
      ref="baseChartRef"
    />
    <!-- <view style="height: 660rpx;"></view> -->
    <!-- </scroll-view> -->
    <view class="wraps">
      <view class="record-more">
        <view class="record-title">
          <view class="line"></view>
          <text>明细记录</text>
        </view>
        <view @tap="detailFun" class="more">
          查看更多
          <!-- <image class="img_more" src="https://ainengli.meilianshuke.com/jkhx/common/more.png" /> -->
          <icon class="iconfont icon-zhankaijiantou img_more" />
        </view>
      </view>
      <view class="content">
        <view class="nodate" v-if="listLoading">
          <up-loading-icon></up-loading-icon>
        </view>
        <view v-else-if="state.taskList && state.taskList.length > 0">
          <indexCardRecord
            :message="messageObj"
            :isSign="isSign"
            @reload="reload"
            @deleteItem="deleteItem"
            @onUpdate="add"
          ></indexCardRecord>
        </view>
        <view class="nodate" v-else>
          <img class="img" src="https://ainengli.meilianshuke.com/jkhx/noData.png" alt="" />
          <view class="nodate_text">
            <text class="name">暂无数据</text>
          </view>
        </view>
      </view>
    </view>
    <view @touchmove.stop.prevent="prevent">
      <up-popup
        :show="show"
        :closeable="true"
        mode="bottom"
        @close="close"
        :custom-style="{ 'max-height': '98vh', overflow: 'auto' }"
        :round="16"
      >
        <HealthPopup
          :poptype="'others'"
          :healthType="state.type"
          :isClick="state.isClick"
          :isShow="show"
          :empi="userInfo.empi"
          :isSign="isSign"
          :uploading="uploading"
          :list="state.healthList"
          :slideInfoList="slideInfoList"
          :picInfo="selectPicInfo"
          @onReset="init"
          @onGoit="goit"
          @onSelectFile="selectFile"
          @onSave1="oldHealthDataSave"
          @onSave2="newHealthDateSave"
          @onSave3="saveReportData"
          @onSave4="oldHealthDataUpdate"
          @measurementFun="measurementFun"
          @timeFun="timeFun"
          ref="healthPopupRef"
        />
      </up-popup>
    </view>
    <!-- 睡眠录入 -->
    <view @touchmove.stop.prevent="prevent">
      <up-popup
        :show="showSleep"
        :closeable="true"
        mode="bottom"
        @close="close"
        :custom-style="{ 'max-height': '98vh', overflow: 'auto' }"
        :round="16"
      >
        <HealthPopup
          :poptype="'sleep'"
          :healthType="state.type"
          :list="state.healthList"
          :isClick="state.isClick"
          :slideInfoList="slideInfoList"
          :empi="userInfo.empi"
          @onReset="init"
          @onGoit="goit"
          @onSave2="newHealthDateSave"
          @timeSleepFun="timeSleepFun"
          ref="sleepPopupRef"
        />
      </up-popup>
    </view>
    <view @touchmove.stop.prevent="prevent">
      <up-popup
        :show="measurementShow"
        :closeable="true"
        mode="bottom"
        @close="goit"
        :custom-style="{
          'max-height': '98vh',
          overflow: 'auto'
        }"
      >
        <HealthPopup
          :poptype="'tips'"
          :healthType="state.type"
          @onGoit="goit"
          @onReset="init"
            />
      </up-popup>
    </view>
    <view @touchmove.stop.prevent="prevent">
      <up-datetime-picker
        :show="dateShow"
        v-model="state.datetime"
        :closeOnClickOverlay="true"
        :minDate="state.minDate"
        :maxDate="new Date().getTime()"
        :mode="state.type == 'water' ? 'date' : 'datetime'"
        @close="closeDateTime"
        @confirm="confirmDateTime"
        @cancel="closeDateTime"
        @change="changeFun"
      />
    </view>
    <!-- sleep 时间 -->
    <view @touchmove.stop.prevent="prevent">
      <up-datetime-picker
        :show="dateSleepShow"
        v-model="state.datetime"
        :closeOnClickOverlay="true"
        :minDate="state.minDate"
        :maxDate="new Date().getTime()"
        mode="datetime"
        @close="closeSleepDateTime"
        @confirm="confirmSleepDateTime"
        @cancel="closeSleepDateTime"
        @change="changeSleepFun"
      />
    </view>
    <!--  -->
    <view @touchmove.stop.prevent="prevent">
      <up-popup :show="abnormalShow" :round="8" mode="center" @close="abnormalClose">
        <view class="abnormalContent">
          <view class="title"> 异常提醒 </view>
          <text class="content">
            {{ warningMap(state.type) }}
          </text>
          <view class="know" @tap="abnormalClose">知道了</view>
        </view>
      </up-popup>
    </view>
    <!-- 排便录入 -->
    <view @touchmove.stop.prevent="prevent">
      <up-popup
        :show="showDefecate"
        :closeable="true"
        mode="bottom"
        @close="showDefecate = false"
        :custom-style="{ 'max-height': '98vh', overflow: 'auto' }"
        :round="16"
      >
        <DefacatePopup
          poptype="defecate"
          :healthType="state.type"
          :list="state.healthList"
          :isClick="state.isClick"
          :slideInfoList="slideInfoList"
          @onReset="init"
          @onGoit="goit"
          @onSave2="newHealthDateSave"
          @toggleOutPopup="toggleOutPopup"
          ref="defecatePopupRef"
          :show="showDefecate"
        />
      </up-popup>
    </view>
    <up-modal
      :show="state.deleteShow"
      :title="'提示'"
      :closeOnClickOverlay="true"
      :showCancelButton="true"
      :confirmColor="'#FF503D'"
      @confirm="deleteSignsInfo"
      @close="cancel"
      @cancel="cancel"
    >
      <view
        style="width: 100%; font-size: 30rpx; font-weight: 400; color: #4e5969; text-align: center"
        >确认要删除该条记录吗?</view
      >
    </up-modal>
    <view class="fixed">
      <button class="cancel_btn" @tap="knowFun">{{ '关于' + getTitleName(type) }}</button>
      <button class="confirm_btn" @tap="add(state.type, 'add')">记录数据</button>
    </view>
  </view>
</template>

<script setup lang="ts">
import NewBaseInfo from './newBaseInfo.vue'
import SleepBaseInfo from './sleepBaseInfo.vue'
import BaseChart from './baseInfo.vue'
import BloodInfo from './bloodInfo.vue'
import BloodSugarInfo from './bloodSugarInfo.vue'
import { ref, reactive, watch, computed, nextTick } from 'vue'
import { onLoad, onShow, onReachBottom } from '@dcloudio/uni-app'
import { debounce, parseTime } from '@/utils/tools'
import { healthInfoMapList, healthInfoSave, healthInfoAll, healthInfoUpdate } from '@/api/hmm'
import { signStatus, uploadCamp, saveCampPic } from '../healthPortrait/healthPortrait.api'
import {
  saveNewIndicator,
  saveReport,
  getNewDetail,
  getWaterSleepDetail,
  signsInfoDelete,
  getSignsList
} from '../healthPortrait/healthPortrait.api'
import indexCardRecord from '../healthPortrait/components/indexCardRecord'
import HealthPopup from '../healthPortrait/components/HealthPopup'
import DefacatePopup from '../healthPortrait/components/defecatePopup'
import { deleteDefecate, getDefecateListByEmpi } from '../../api/defecate'

const type = ref('')
const userInfo = ref({})

const deleteIndex = ref(0)
const swipeRef = ref()
const baseChartRef = ref(null)
const bloodChartRef = ref(null)
const bloodSugarChartRef = ref(null)
const newBaseChartRef = ref(null)
const sleepChartRef = ref(null)
const healthPopupRef = ref(null)
const sleepPopupRef = ref(null)
const defecatePopupRef = ref(null)

const weightInfo = {
  title: '体重',
  value: 'weight',
  color: '#FF813C',
  unit: '单位: kg',
  offsetX: 0,
  min: 0,
  max: 200,
  splitNumber: 5
}
const whrInfo = {
  title: '腰臀比',
  value: 'whr',
  color: '#8B89E9',
  unit: '',
  offsetX: 0,
  min: 0,
  max: 1.5,
  splitNumber: 5,
  markLine: {
    z: 1,
    type: 'dash',
    dashLength: 8,
    data: [
      {
        value: 0.85,
        lineColor: '#8B89E9',
        showLabel: true,
        labelAlign: 'right',
        labelPadding: 1,
        labelBgOpacity: 0,
        labelBgColor: '#fff',
        labelFontSize: 12
      }
    ]
  }
}
const heartInfo = {
  title: '心率',
  value: 'heart_rate',
  color: '#0CB67C',
  unit: '单位: 次/分',
  offsetX: 20,
  min: 0,
  max: 180,
  splitNumber: 6,
  markLine: {
    z: 1,
    type: 'dash',
    dashLength: 8,
    data: [
      {
        value: 60,
        lineColor: '#0CB67C',
        showLabel: true,
        labelAlign: 'right',
        labelPadding: 1,
        labelBgOpacity: 0,
        labelBgColor: '#fff',
        labelFontSize: 12
      },
      {
        value: 100,
        lineColor: '#0CB67C',
        showLabel: true,
        labelAlign: 'right',
        labelPadding: 1,
        labelBgOpacity: 0,
        labelBgColor: '#fff',
        labelFontSize: 12
      }
    ]
  }
}
const oxygenInfo = {
  title: '血氧',
  value: 'spo2',
  color: '#50B5FE',
  unit: '单位: %',
  offsetX: 0,
  min: 0,
  max: 100,
  splitNumber: 5,
  markLine: {
    z: 1,
    type: 'dash',
    dashLength: 8,
    data: [
      {
        value: 95,
        lineColor: '#50B5FE',
        showLabel: true,
        labelAlign: 'right',
        labelPadding: 1,
        labelBgOpacity: 0,
        labelBgColor: '#fff',
        labelFontSize: 12,
        labelOffsetY: 10
      },
      {
        value: 100,
        lineColor: '#50B5FE',
        showLabel: true,
        labelAlign: 'right',
        labelPadding: 1,
        labelBgOpacity: 0,
        labelBgColor: '#fff',
        labelFontSize: 12,
        labelOffsetY: -10
      }
    ]
  }
}

const ketoneInfo = {
  title: '血酮',
  value: 'blood_ketone',
  color: '#FF813C',
  unit: '单位: mmol/L',
  offsetX: 0,
  min: 0,
  max: 4,
  splitNumber: 5,
  markLine: {
    z: 1,
    type: 'dash',
    dashLength: 8,
    data: [
      {
        value: 0.03,
        lineColor: '#FF813C',
        showLabel: true,
        labelAlign: 'right',
        labelPadding: 1,
        labelBgOpacity: 0,
        labelFontColor: '#FF813C',
        labelBgColor: '#fff',
        labelFontSize: 12,
        labelOffsetY: 10
      },
      {
        value: 0.3,
        lineColor: '#FF813C',
        showLabel: true,
        labelAlign: 'right',
        labelPadding: 1,
        labelBgOpacity: 0,
        labelFontColor: '#FF813C',
        labelBgColor: '#fff',
        labelFontSize: 12,
        labelOffsetY: -10
      }
    ]
  }
}
const uricAcidInfo = {
  title: '尿酸',
  value: 'uric_acid',
  color: '#3C5CFF',
  unit: '单位: umol/L',
  offsetX: 0,
  min: 0,
  max: 600,
  splitNumber: 5,
  markLine: {
    z: 1,
    type: 'dash',
    dashLength: 8,
    data: [
      {
        value: 89,
        lineColor: '#3C5CFF',
        showLabel: true,
        labelAlign: 'right',
        labelPadding: 1,
        labelBgOpacity: 0,
        labelFontColor: '#3C5CFF',
        labelBgColor: '#fff',
        labelFontSize: 12,
        labelOffsetY: 10
      },
      {
        value: 357,
        lineColor: '#3C5CFF',
        showLabel: true,
        labelAlign: 'right',
        labelPadding: 1,
        labelBgOpacity: 0,
        labelFontColor: '#3C5CFF',
        labelBgColor: '#fff',
        labelFontSize: 12,
        labelOffsetY: -10
      }
    ]
  }
}
const sleepInfo = {
  title: '睡眠',
  value: 'sleep',
  color: ['transparent', '#5089FE'],
  unit: '',
  // offsetX: 0,
  // yAxisType: 'value',
  splitNumber: 6,
  extra: {
    column: {
      type: 'stack',
      width: 8,
      activeBgColor: '#000000',
      activeBgOpacity: 0.08,
      seriesGap: 0,
      meterBorder: 0,
      labelPosition: 'center',
      barBorderRadius: [4, 4, 4, 4]
    },
    tooltip: {
      showBox: true, // 显示 tooltip
      showArrow: true
    }
  }
}
const waterInfo = {
  title: '饮水',
  value: 'water',
  color: '#FF8F18',
  unit: '单位: ml',
  offsetX: 0,
  min: 0,
  max: 4000,
  splitNumber: 5,
  yAxisType: 'value',
  markLine: {
    z: 1,
    type: 'dash',
    dashLength: 8,
    data: [
      {
        value: 2000,
        lineColor: '#FF8F18',
        showLabel: true,
        labelAlign: 'right',
        labelPadding: 1,
        labelBgOpacity: 0,
        labelFontColor: '#FF8F18',
        labelBgColor: '#fff',
        labelFontSize: 12,
        labelOffsetY: 10
      }
    ]
  }
}
const bloodFatInfo = {
  title: '血脂',
  value: 'blood_fat',
  color: ['#0CB67C', '#EE4A4A', '#369AFF', '#FEC21D'],
  unit: '单位: mmol/L',
  offsetX: 0,
  min: 0,
  max: 6,
  splitNumber: 5,
  show: true
}
const liverFunctionInfo = {
  title: '肝功能',
  value: 'liver_function',
  color: ['#1CD7AE', '#ED5B5B', '#FF8746'],
  unit: '单位: U/L',
  offsetX: 0,
  min: 0,
  max: 60,
  splitNumber: 5,
  show: true
}
const defecateInfo = {
  title: '排便',
  value: 'defecate',
  color: '#FF8F18',
  offsetX: 0,
  min: 0,
  max: 10,
  splitNumber: 5
}
const state = reactive({
  type: '',
  editType: '',
  filtrate: {
    //请求参数
    size: 20, // 条数
    num: 1 // 页数
  },
  taskList: [], //数据
  show: false,
  inputValue: '',
  maxNum: 100, //最多输入字数
  getObj: {},
  loadstatus: 'nomore',
  slideRuleType: '',
  slideRuleTypeDefault: false,
  slideRuleShow: true,
  isClick: false,
  showTest: false,
  deleteShow: false,
  userInfo: {},
  bloodSugarActive: 0,
  current: 60, //刻度指向的位置
  maxValue: 150,
  ruleType: 'cm',
  healthList: {},
  datetime: '',
  minDate: 0,
  time: '',
  datetimeNew: '',
  wakeupDate: '',
  sleepDate: ''
})
const listLoading = ref(false)
const sleepTimeType = ref('')
const measurementShow = ref(false)
const show = ref(false)
const showSleep = ref(false)
const dateShow = ref(false)
const dateSleepShow = ref(false)
const abnormalShow = ref(false)
const empi = ref<string>('')
const updateId = ref('')
const messageObj = ref<any>({
  taskList: [],
  type: '',
  loadstatus: 'loadmore'
})
const slideInfoList = ref<any>([])
const showDefecate = ref(false)

onLoad((option: any) => {
  type.value = option.type ? option.type : ''
  if (option.type) {
    if (option.type == 'blood_pressure') {
      state.type = 'sbp'
    } else if (option.type == 'heart') {
      state.type = 'heart_rate'
    } else if (option.type == 'blood_oxygen') {
      state.type = 'spo2'
    } else if (option.type == 'BMI') {
      state.type = 'bmi'
    } else {
      state.type = option.type
    }
    messageObj.value.type = state.type
  }
  userInfo.value = uni.getStorageSync('userInfo')
    ? JSON.parse(uni.getStorageSync('userInfo')).patientInfo
    : {}
  empi.value = option.empi ? option.empi : userInfo.value.empi
  uni.setNavigationBarTitle({
    title: getTitleName(type.value)
  })
})
onShow(() => {
  init()
  if (state.type == 'bmi') {
    getStatus()
  }
  state.datetime = parseTime(new Date().getTime(), '{y}-{m}-{d} {h}:{i}')
  getMinTime()
  state.userInfo = uni.getStorageSync('userInfo')
    ? JSON.parse(uni.getStorageSync('userInfo')).patientInfo
    : {}
  userInfo.value = JSON.parse(uni.getStorageSync('userInfo')).patientInfo
  whrInfo.markLine.data[0].value = userInfo.value.gender == '女性' ? 0.85 : 0.9
  uricAcidInfo.markLine.data[0].value = userInfo.value.gender == '女性' ? 89 : 149
  uricAcidInfo.markLine.data[1].value = userInfo.value.gender == '女性' ? 357 : 416
})
onReachBottom(() => {
  if (state.loadstatus != 'nomore') {
    loadMoreData()
  }
})

watch(
  () => state.inputValue,
  (newVal, oldVal) => {
    if (newVal && newVal.length > 100) {
      state.inputValue = newVal.substring(0, 100)
    }
  },
  {
    immediate: true
  }
)

const init = () => {
  state.taskList = []
  messageObj.value.taskList = []
  uni.showLoading({
    title: '加载中'
  })
  if (
    state.type == 'blood_ketone' ||
    state.type == 'uric_acid' ||
    state.type == 'blood_fat' ||
    state.type == 'liver_function' ||
    state.type == 'blood_sugar'
  ) {
    getNewList()
  } else if (state.type == 'water' || state.type == 'sleep') {
    getWaterSleepList()
  } else if (state.type == 'defecate') {
    getDefecateList()
  } else {
    getList()
  }
  healthInfoAll(empi.value).then((res) => {
    uni.hideLoading()
    if (res.code == 0) {
      state.healthList = res.data
    } else {
      state.healthList = {}
    }
  })
  // 图表初始化
  if (baseChartRef.value) {
    switch (type.value) {
      case 'BMI':
        baseChartRef.value.getData(weightInfo.value, weightInfo.title)
        break
      case 'whr':
        baseChartRef.value.getData(whrInfo.value, whrInfo.title)
        break
      case 'heart_rate':
        baseChartRef.value.getData(heartInfo.value, heartInfo.title)
        break
      case 'blood_oxygen':
        baseChartRef.value.getData(oxygenInfo.value, oxygenInfo.title)
      case 'defecate':
        baseChartRef.value.getData(defecateInfo.value, defecateInfo.title)
        break
    }
  }
  if (bloodChartRef.value) {
    bloodChartRef.value.getData('sbp', '收缩压')
  }
  if (bloodSugarChartRef.value) {
    bloodSugarChartRef.value.tabChange('fbg', '空腹/餐前血糖')
  }
  if (newBaseChartRef.value) {
    switch (type.value) {
      case 'blood_ketone':
        newBaseChartRef.value.getData(ketoneInfo.value, ketoneInfo.title)
        break
      case 'uric_acid':
        newBaseChartRef.value.getData(uricAcidInfo.value, uricAcidInfo.title)
        break
      case 'water':
        newBaseChartRef.value.getData(waterInfo.value, waterInfo.title)
        break
      case 'blood_fat':
        newBaseChartRef.value.getData(bloodFatInfo.value, bloodFatInfo.title)
        break
      case 'liver_function':
        newBaseChartRef.value.getData(liverFunctionInfo.value, liverFunctionInfo.title)
        break
    }
  }
  if (sleepChartRef.value) {
    sleepChartRef.value.getData(sleepInfo.value, sleepInfo.title)
  }
}

const reload = () => {
  // state.filtrate.num++
  getList()
}

const getTitleName = (val: string) => {
  switch (val) {
    case 'BMI':
      return '体重'
    case 'whr':
      return '腰臀比'
    case 'blood_pressure':
      return '血压'
    case 'heart_rate':
      return '心率'
    case 'blood_sugar':
      return '血糖'
    case 'blood_oxygen':
      return '血氧'
    case 'blood_ketone':
      return '血酮'
    case 'uric_acid':
      return '尿酸'
    case 'sleep':
      return '睡眠'
    case 'water':
      return '饮水'
    case 'blood_fat':
      return '血脂'
    case 'liver_function':
      return '肝功能'
    case 'defecate':
      return '排便'
    default:
      return ''
  }
}

const knowFun = () => {
  switch (type.value) {
    case 'blood_sugar':
      uni.navigateTo({
        url: '/module/src/pages/healthPortrait/detail/bloodSugar'
      })
      return
    case 'blood_oxygen':
      uni.navigateTo({
        url: '/module/src/pages/healthPortrait/detail/bloodOxygen'
      })
      return
    case 'blood_ketone':
      uni.navigateTo({
        url: '/module/src/pages/healthPortrait/detail/bloodKetone'
      })
      return
    case 'uric_acid':
      uni.navigateTo({
        url: '/module/src/pages/healthPortrait/detail/uricAcid'
      })
      return
    case 'sleep':
      uni.navigateTo({
        url: '/module/src/pages/healthPortrait/detail/sleep'
      })
      return
    case 'water':
      uni.navigateTo({
        url: '/module/src/pages/healthPortrait/detail/water'
      })
      return
    case 'blood_fat':
      uni.navigateTo({
        url: '/module/src/pages/healthPortrait/detail/bloodFat'
      })
      return
    case 'liver_function':
      uni.navigateTo({
        url: '/module/src/pages/healthPortrait/detail/liverFunction'
      })
      return
    case 'heart_rate':
      uni.navigateTo({
        url: '/module/src/pages/healthPortrait/detail?type=heart'
      })
      return
    case 'defecate':
      uni.navigateTo({
        url: '/module/src/pages/healthPortrait/detail/defecate'
      })
      return
    default:
      uni.navigateTo({
        url: '/module/src/pages/healthPortrait/detail?type=' + type.value
      })
      return
  }
}
// 获取数据
const getList = () => {
  if (state.taskList.length == 0) {
    listLoading.value = true
  }
  state.loadstatus = 'loading'
  messageObj.value.loadstatus = 'loading'
  const param = {
    empi: empi.value,
    page: state.filtrate.num,
    limit: state.filtrate.size,
    itemList: []
  }
  if (state.type == 'fbg') {
    const obj1 = 'fbg'
    const obj2 = 'pbg'
    param.itemList.push(obj1)
    param.itemList.push(obj2)
  } else {
    param.itemList.push(state.type)
  }
  getSignsList(param).then((res) => {
    listLoading.value = false
    if (res.code == 0) {
      if (res.data && res.data.length > 0) {
        // 拼接图片地址
        if (state.type == 'bmi') {
          res.data.forEach((val) => {
            if (val.campWieghtPics && val.campWieghtPics.length > 0) {
              val.campWieghtPics.forEach((item) => {
                item.url = item.picBaseUrl + item.picUrl
                item.relativePath = item.picUrl
                item.name = item
                item.status = 'success'
                item.extname = 'png'
              })
            } else {
              val.campWieghtPics = []
            }
          })
        }
        if (state.taskList.length > 0) {
          state.taskList = state.taskList.concat(res.data)
          messageObj.value.taskList = state.taskList?.slice(0, 20)
        } else {
          state.taskList = res.data
          messageObj.value.taskList = state.taskList?.slice(0, 20)
        }
        if (res.data.length < 20 || state.taskList.length >= 20) {
          state.loadstatus = 'nomore'
          messageObj.value.loadstatus = 'nomore'
        } else {
          state.loadstatus = 'loadmore'
          messageObj.value.loadstatus = 'loadmore'
        }
      } else {
        state.loadstatus = 'nomore'
        messageObj.value.loadstatus = 'nomore'
      }
    } else {
      state.filtrate.num--
      state.loadstatus = 'error'
      messageObj.value.loadstatus = 'error'
    }
  })
}
const getNewList = () => {
  listLoading.value = true
  state.loadstatus = 'loading'
  messageObj.value.loadstatus = 'loading'
  const param = {
    empi: userInfo.value.empi,
    indicatorKey: state.type
  }
  getNewDetail(param).then((res: any) => {
    listLoading.value = false
    if (res.code == 0) {
      if (res.data && res.data.length > 0) {
        const seenDates = new Set()
        state.taskList = res.data.map((item) => {
          const date = item.report.checkTime.split(' ')[0] // 提取日期部分
          const time = item.report.checkTime
          if (seenDates.has(date)) {
            // 如果日期已出现，隐藏 checkTime
            return { ...item, report: { ...item.report, checkTime: null, realTime: time } }
          } else {
            // 如果日期未出现，保留 checkTime
            seenDates.add(date)
            return item
          }
        })
        messageObj.value.taskList = state.taskList?.slice(0, 20)
        // 这个接口似乎没有分页，并且加载更多也没有加载这个接口，所以先这样改了
        state.loadstatus = 'nomore'
        messageObj.value.loadstatus = 'nomore'
        // if (res.data.length < 20) {
        //   state.loadstatus = 'nomore'
        //   messageObj.value.loadstatus = 'nomore'
        // } else {
        //   state.loadstatus = 'loadmore'
        //   messageObj.value.loadstatus = 'loadmore'
        // }
      } else {
        state.taskList = []
        messageObj.value.taskList = []
        state.loadstatus = 'nomore'
        messageObj.value.loadstatus = 'nomore'
      }
    } else {
      state.filtrate.num--
      state.loadstatus = 'error'
      messageObj.value.loadstatus = 'error'
    }
  })
}

const getWaterSleepList = () => {
  listLoading.value = true
  state.loadstatus = 'loading'
  messageObj.value.loadstatus = 'loading'
  const param = {
    empi: userInfo.value.empi,
    itemList: [state.type],
    page: 1,
    limit: 10
  }
  getWaterSleepDetail(param).then((res: any) => {
    listLoading.value = false
    if (res.code == 0) {
      const seenDates = new Set()
      if (res.data && res.data.length > 0) {
        if (state.type == 'sleep') {
          state.taskList = res.data.map((item: any) => {
            const date = item.collectTime.split(' ')[0]
            if (seenDates.has(date)) {
              return {
                ...item,
                collectTime: null,
                paramValue: JSON.parse(item.paramValue)
              }
            } else {
              seenDates.add(date)
              return {
                ...item,
                paramValue: JSON.parse(item.paramValue)
              }
            }
          })
          // 解决IOS下不兼容yyyy-MM-dd格式问题
          state.taskList.forEach((val) => {
            val.paramValue.sleepTime = parseTime(val.paramValue.sleepTime, '{y}/{m}/{d} {h}:{i}')
            val.paramValue.weekupTime = parseTime(val.paramValue.weekupTime, '{y}/{m}/{d} {h}:{i}')
          })
          messageObj.value.taskList = state.taskList?.slice(0, 20)
        } else {
          state.taskList = res.data
          messageObj.value.taskList = state.taskList?.slice(0, 20)
        }
        // 这个接口似乎分页没有生效，并且加载更多也没有加载这个接口，所以先这样改了
        state.loadstatus = 'nomore'
        messageObj.value.loadstatus = 'nomore'
        // if (res.data.length < 20) {
        //   state.loadstatus = 'nomore'
        //   messageObj.value.loadstatus = 'nomore'
        // } else {
        //   state.loadstatus = 'loadmore'
        //   messageObj.value.loadstatus = 'loadmore'
        // }
      } else {
        state.taskList = []
        messageObj.value.taskList = []
        state.loadstatus = 'nomore'
        messageObj.value.loadstatus = 'nomore'
      }
    } else {
      state.filtrate.num--
      state.loadstatus = 'error'
      messageObj.value.loadstatus = 'error'
    }
  })
}
const getDefecateList = () => {
  listLoading.value = true
  state.loadstatus = 'loading'
  messageObj.value.loadstatus = 'loading'
  const param = {
    empi: userInfo.value.empi
  }
  getDefecateListByEmpi(param).then((res: any) => {
    listLoading.value = false
    if (res.code == 0) {
      state.taskList = res.data
      state.loadstatus = 'nomore'
      messageObj.value.taskList = state.taskList?.slice(0, 20)
      messageObj.value.loadstatus = 'nomore'
    } else {
      state.filtrate.num--
      state.loadstatus = 'error'
      messageObj.value.loadstatus = 'error'
    }
  })
}
const loadMoreData = () => {
  state.filtrate.num++
  getList()
}
const prevent = () => {}

const warningMap = (type: string) => {
  let text = ''
  switch (type) {
    case 'bmi':
      text = '您的BMI异常，请关注体重数据'
      break
    case 'whr':
      text = '您的腰臀比数据异常，请关注'
      break
    case 'sbp':
      text = '您的血压异常，建议您增加监测次数并咨询医生'
      break
    case 'heart_rate':
      text = '您的心率异常，建议您增加监测次数并咨询医生'
      break
    case 'blood_sugar':
      text = '您的血糖异常，建议您增加监测次数并咨询医生'
      break
    case 'spo2':
      text = '您的血氧异常，建议您增加监测次数并咨询医生'
      break
    case 'blood_ketone':
      text = '您的血酮异常，建议您增加监测次数并咨询医生'
      break
    case 'uric_acid':
      text = '您的尿酸异常，建议您增加监测次数并咨询医生'
      break
    case 'sleep':
      text = '您的睡眠时间过短，请注意'
      break
    case 'blood_fat':
      text = '您的血脂异常，建议您增加监测次数并咨询医生'
      break
    case 'liver_function':
      text = '您的肝功能异常，建议您增加监测次数并咨询医生'
      break
  }
  return text
}

const abnormalClose = () => {
  abnormalShow.value = false
  init()
}
const setSlideInfo = (type: string, editItem: any) => {
  // 整合健康监测数据
  slideInfoList.value = []
  switch (state.type) {
    case 'bmi':
      slideInfoList.value[0] = {
        value:
          type == 'edit' && Object.keys(editItem).length !== 0
            ? editItem.height
            : state.healthList.height.itemValue
            ? Number(state.healthList.height.itemValue)
            : 170,
        maxValue: 250,
        name: '身高',
        unit: 'cm'
      }
      slideInfoList.value[1] = {
        value:
          type == 'edit' && Object.keys(editItem).length !== 0
            ? editItem.weight
            : state.healthList.weight.itemValue
            ? Number(state.healthList.weight.itemValue)
            : 65,
        maxValue: 250,
        name: '体重',
        unit: 'kg'
      }
      break
    case 'whr':
      slideInfoList.value[0] = {
        value:
          type == 'edit' && Object.keys(editItem).length !== 0
            ? editItem.waist
            : state.healthList.waist.itemValue
            ? Number(state.healthList.waist.itemValue)
            : 85,
        maxValue: 200,
        name: '腰围',
        unit: 'cm'
      }
      slideInfoList.value[1] = {
        value:
          type == 'edit' && Object.keys(editItem).length !== 0
            ? editItem.hip
            : state.healthList.hip.itemValue
            ? Number(state.healthList.hip.itemValue)
            : 100,
        maxValue: 200,
        name: '臀围',
        unit: 'cm'
      }
      break
    case 'sbp':
      slideInfoList.value[0] = {
        value:
          type == 'edit' && Object.keys(editItem).length !== 0
            ? editItem.sbp
            : state.healthList.sbp.itemValue
            ? Number(state.healthList.sbp.itemValue)
            : 120,
        maxValue: 300,
        name: '收缩压',
        unit: 'mmHg'
      }
      slideInfoList.value[1] = {
        value:
          type == 'edit' && Object.keys(editItem).length !== 0
            ? editItem.dbp
            : state.healthList.dbp.itemValue
            ? Number(state.healthList.dbp.itemValue)
            : 80,
        maxValue: 300,
        name: '舒张压',
        unit: 'mmHg'
      }
      slideInfoList.value[2] = {
        value:
          type == 'edit' && Object.keys(editItem).length !== 0
            ? editItem.pulseRate
            : state.healthList.pulseRate.itemValue
            ? Number(state.healthList.pulseRate.itemValue)
            : 75,
        maxValue: 180,
        name: '脉搏',
        unit: '次/分'
      }
      break
    case 'heart_rate':
      slideInfoList.value[0] = {
        value:
          type == 'edit' && Object.keys(editItem).length !== 0
            ? editItem.heartRate
            : state.healthList.heartRate.itemValue
            ? Number(state.healthList.heartRate.itemValue)
            : 75,
        maxValue: 180,
        name: '心率',
        unit: '次/分'
      }
      break
    case 'blood_sugar':
      slideInfoList.value[0] = {
        value:
          type == 'edit' && Object.keys(editItem).length !== 0
            ? editItem.details[0].indicatorValue
            : state.healthList.pbg && state.healthList.pbg.itemValue
            ? Number(state.healthList.pbg.itemValue)
            : state.healthList.fbg && state.healthList.fbg.itemValue
            ? Number(state.healthList.fbg.itemValue)
            : 5.5,
        maxValue: 30,
        name: '血糖',
        unit: 'mmol/L'
      }
      break
    case 'spo2':
      slideInfoList.value[0] = {
        value:
          type == 'edit' && Object.keys(editItem).length !== 0
            ? editItem.spo2
            : state.healthList.spo2.itemValue
            ? Number(state.healthList.spo2.itemValue)
            : 97,
        maxValue: 100,
        name: '血氧饱和度',
        unit: '%'
      }
      break
    case 'blood_ketone':
      slideInfoList.value[0] = {
        value:
          type == 'edit' && Object.keys(editItem).length !== 0
            ? editItem.details[0].indicatorValue
            : state.healthList.blood_ketone && state.healthList.blood_ketone.indicatorList
            ? Number(state.healthList.blood_ketone.indicatorList[0].indicatorValue)
            : 0.17,
        maxValue: 4.0,
        name: '血酮',
        unit: 'mmoL/L'
      }
      break
    case 'uric_acid':
      slideInfoList.value[0] = {
        value:
          type == 'edit' && Object.keys(editItem).length !== 0
            ? editItem.details[0].indicatorValue
            : state.healthList.uric_acid.indicatorList
            ? Number(state.healthList.uric_acid.indicatorList[0].indicatorValue)
            : 200,
        maxValue: 600,
        name: '尿酸',
        unit: 'umol/L'
      }
      break
    case 'water':
      if (state.healthList.water && state.taskList.length > 0) {
        state.healthList.water.itemValue = state.taskList[0].drinkList[0].paramValue
      }
      slideInfoList.value[0] = {
        value:
          type == 'edit' && Object.keys(editItem).length !== 0
            ? Number(editItem.paramValue)
            : state.healthList.water && state.healthList.water.itemValue
            ? Number(state.healthList.water.itemValue)
            : 350,
        maxValue: 4000,
        name: '饮水',
        unit: 'ml'
      }
      break
    case 'blood_fat':
      const listData =
        state.healthList.blood_fat && state.healthList.blood_fat.indicatorList
          ? state.healthList.blood_fat.indicatorList
          : []
      const total_cholesterol = listData.filter(
        (item) => item.indicatorKey == 'total_cholesterol'
      )[0]
      const tg = listData.filter((item) => item.indicatorKey == 'tg')[0]
      const hdlc = listData.filter((item) => item.indicatorKey == 'hdlc')[0]
      const ldlc = listData.filter((item) => item.indicatorKey == 'ldlc')[0]
      slideInfoList.value[0] = {
        value:
          type == 'edit' && Object.keys(editItem).length !== 0
            ? editItem.details[0].indicatorValue
            : total_cholesterol
            ? Number(total_cholesterol.indicatorValue)
            : 4.0,
        maxValue: 6.0,
        name: '总胆固醇',
        unit: 'mmol/L'
      }
      slideInfoList.value[1] = {
        value:
          type == 'edit' && Object.keys(editItem).length !== 0
            ? editItem.details[1].indicatorValue
            : tg
            ? Number(tg.indicatorValue)
            : 1.0,
        maxValue: 3.0,
        name: '甘油三酯',
        unit: 'mmol/L'
      }
      slideInfoList.value[2] = {
        value:
          type == 'edit' && Object.keys(editItem).length !== 0
            ? editItem.details[2].indicatorValue
            : hdlc
            ? Number(hdlc.indicatorValue)
            : 1.3,
        maxValue: 3.0,
        name: '高密度脂蛋白',
        unit: 'mmol/L'
      }
      slideInfoList.value[3] = {
        value:
          type == 'edit' && Object.keys(editItem).length !== 0
            ? editItem.details[3].indicatorValue
            : ldlc
            ? Number(ldlc.indicatorValue)
            : 3.0,
        maxValue: 3.0,
        name: '低密度脂蛋白',
        unit: 'mmol/L'
      }
      break
    case 'liver_function':
      const liver_functionData =
        state.healthList.blood_fat && state.healthList.blood_fat.indicatorList
          ? state.healthList.blood_fat.indicatorList
          : []
      const got = liver_functionData.filter((item) => item.indicatorKey == 'got')[0]
      const gpt = liver_functionData.filter((item) => item.indicatorKey == 'gpt')[0]
      const ygt = liver_functionData.filter((item) => item.indicatorKey == 'ygt')[0]
      slideInfoList.value[0] = {
        value:
          type == 'edit' && Object.keys(editItem).length !== 0
            ? editItem.details[0].indicatorValue
            : got
            ? Number(got.indicatorValue)
            : 28,
        maxValue: 60,
        name: '谷草转氨酶',
        unit: 'U/L'
      }
      slideInfoList.value[1] = {
        value:
          type == 'edit' && Object.keys(editItem).length !== 0
            ? editItem.details[1].indicatorValue
            : gpt
            ? Number(gpt.indicatorValue)
            : 30,
        maxValue: 60,
        name: '谷丙转氨酶',
        unit: 'U/L'
      }
      slideInfoList.value[2] = {
        value:
          type == 'edit' && Object.keys(editItem).length !== 0
            ? editItem.details[2].indicatorValue
            : ygt
            ? Number(ygt.indicatorValue)
            : 26,
        maxValue: 60,
        name: 'Y-谷氨酰转肽酶',
        unit: 'U/L'
      }
      break
  }
  slideInfoList.value.forEach((item) => {
    item.init = item.value
    item.currentScore = item.value
  })
}
const typeMap = {
  sleep: { show: showSleep, ref: sleepPopupRef },
  defecate: { show: showDefecate, ref: defecatePopupRef }
  // 其他类型可以继续加
}

const add = (name: string, type: string, editItem: any) => {
  if (
    type == 'add' ||
    (type == 'edit' &&
    editItem.dataSource != '华为运动健康' || 
    (editItem.report && 
    editItem.report.reportSource && 
    editItem.report.reportSource != '华为运动健康'))) {
    const popup = typeMap[state.type]
    if (popup) {
      popup.show.value = true
      popup.ref.value.add(name, type, editItem)
    } else {
      show.value = true
      healthPopupRef.value.add(name, type, editItem)
    }
    console.log('设置选中信息', editItem)
    setSlideInfo(type, editItem)
    setSignId(editItem)
  }
}
const measurementFun = () => {
  if (state.type == 'bmi' || state.type == 'sbp' || state.type == 'blood_sugar') {
    measurementShow.value = true
    show.value = false
    showSleep.value = false
  }
}
const timeFun = (time) => {
  show.value = false
  dateShow.value = true
  state.datetime = time ? new Date(time).getTime() : ''
}
const timeSleepFun = (date: any, type: string) => {
  console.log('睡眠时间', date, type)
  sleepTimeType.value = type
  showSleep.value = false
  dateSleepShow.value = true
  // state.datetime = parseTime(date, '{y}-{m}-{d} {h}:{i}')
  state.datetime = new Date(date).getTime()
}
const getMinTime = () => {
  const date = new Date()
  date.setFullYear(new Date().getFullYear())
  date.setMonth(0)
  date.setDate(1)
  date.setHours(0)
  date.setMinutes(0)
  state.minDate = date.getTime()
}
// sleep
const closeSleepDateTime = () => {
  showSleep.value = true
  dateSleepShow.value = false
}
const confirmSleepDateTime = () => {
  showSleep.value = true
  dateSleepShow.value = false
  if (state.datetimeNew) {
    if (sleepTimeType.value == 'sleep') {
      state.sleepDate = state.datetimeNew.replace(/\//g, '-')
      sleepPopupRef.value.setSleepTime(state.sleepDate)
    } else {
      state.wakeupDate = state.datetimeNew.replace(/\//g, '-')
      sleepPopupRef.value.setWakeupTime(state.wakeupDate)
    }
  } else {
    if (sleepTimeType.value == 'sleep') {
      state.sleepDate = parseTime(new Date().getTime(), '{y}-{m}-{d} {h}:{i}').replace(/\//g, '-')
      sleepPopupRef.value.setSleepTime(state.sleepDate)
    } else {
      state.wakeupDate = parseTime(new Date().getTime(), '{y}-{m}-{d} {h}:{i}').replace(/\//g, '-')
      sleepPopupRef.value.setWakeupTime(state.wakeupDate)
    }
  }
}
const changeSleepFun = (item) => {
  const data = parseTime(new Date(item.value).getTime(), '{y}-{m}-{d} {h}:{i}')
  state.datetimeNew = data
}
const oldHealthDataSave = async (param: any) => {
  if (state.type == 'bmi' && isSign.value) {
    param.campWieghtPics = getPicList()
  }
  healthInfoSave(param)
    .then((res) => {
      uni.hideLoading()
      if (res.code == 0) {
        if (res.data == 'true') {
          show.value = false
          showSleep.value = false
          abnormalShow.value = true
        } else {
          uni.showToast({
            title: '提交成功',
            icon: 'none',
            duration: 2000
          })
          setTimeout(() => {
            show.value = false
            showSleep.value = false
            init()
          }, 2000)
        }
      }
    })
    .catch((err) => {
      state.isClick = false
    })
}

const oldHealthDataUpdate = async (param: any) => {
  if (state.type == 'bmi' && isSign.value) {
    param.campWieghtPics = getPicList()
  }
  healthInfoUpdate(param)
    .then((res) => {
      uni.hideLoading()
      if (res.code == 0) {
        if (res.data == 'true') {
          show.value = false
          showSleep.value = false
          abnormalShow.value = true
        } else {
          uni.showToast({
            title: '提交成功',
            icon: 'none',
            duration: 2000
          })
          setTimeout(() => {
            show.value = false
            showSleep.value = false
            init()
          }, 2000)
        }
      }
    })
    .catch((err) => {
      state.isClick = false
    })
}
/// 新指标保存
const newHealthDateSave = (param: any) => {
  saveNewIndicator(param)
    .then((res) => {
      uni.hideLoading()
      if (res.code == 0) {
        if (res.data == true && state.type != 'water') {
          show.value = false
          showSleep.value = false
          abnormalShow.value = true
        } else {
          uni.showToast({
            title: '提交成功',
            icon: 'none',
            duration: 1500
          })
          setTimeout(() => {
            show.value = false
            showSleep.value = false
            init()
          }, 2000)
        }
      }
    })
    .catch((err) => {
      state.isClick = false
    })
}

// 保存报告
const saveReportData = (param: any) => {
  saveReport(param)
    .then((res) => {
      uni.hideLoading()
      if (res.code == 0) {
        if (res.data == 'true') {
          show.value = false
          showSleep.value = false
          abnormalShow.value = true
        } else {
          uni.showToast({
            title: '提交成功',
            icon: 'none',
            duration: 1500
          })
          setTimeout(() => {
            show.value = false
            showSleep.value = false
            init()
          }, 2000)
        }
      }
    })
    .catch((err) => {
      state.isClick = false
    })
}
const closeDateTime = () => {
  show.value = true
  if (state.slideRuleShow == true) {
    state.slideRuleShow = !state.slideRuleShow
    setTimeout(() => {
      state.slideRuleShow = !state.slideRuleShow
    }, 20)
  }
  dateShow.value = false
}
const confirmDateTime = () => {
  show.value = true
  dateShow.value = false
  if (state.slideRuleShow == true) {
    state.slideRuleShow = !state.slideRuleShow
    setTimeout(() => {
      state.slideRuleShow = !state.slideRuleShow
    }, 20)
  }
  if (state.datetimeNew) {
    state.time = state.datetimeNew.replace(/\//g, '-')
  } else {
    state.time = parseTime(new Date().getTime(), '{y}-{m}-{d} {h}:{i}').replace(/\//g, '-')
  }
  healthPopupRef.value.setTime(state.time)
}
const changeFun = (item) => {
  const data = parseTime(new Date(item.value).getTime(), '{y}-{m}-{d} {h}:{i}')
  state.datetimeNew = data
}
const goit = () => {
  measurementShow.value = false
  if (state.slideRuleShow == true) {
    state.slideRuleShow = !state.slideRuleShow
    setTimeout(() => {
      state.slideRuleShow = !state.slideRuleShow
    }, 20)
  }
  show.value = true
}
const close = () => {
  show.value = false
  showSleep.value = false
}
const detailFun = () => {
  uni.navigateTo({
    url: '/module/src/pages/healthPortrait/healthDataRecord?type=' + state.type
  })
}
const deleteItem = (item: any) => {
  if (
    state.type == 'blood_ketone' ||
    state.type == 'blood_sugar' ||
    state.type == 'uric_acid' ||
    state.type == 'liver_function' ||
    state.type == 'blood_fat'
  ) {
    updateId.value = item.report.id
  } else {
    updateId.value = item.id
  }
  state.deleteShow = true
}
const deleteSignsInfo = () => {
  if (state.type === 'defecate') {
    deleteDefecate({ id: updateId.value }).then((res) => {
      state.deleteShow = false
      uni.showToast({
        title: '删除成功',
        icon: 'none',
        duration: 2000
      })
      init()
    })
    return
  }
  let deleteParam = [{
    id: updateId.value,
    paramKey: state.type
  }]
  signsInfoDelete(deleteParam).then((res) => {
    state.deleteShow = false
    uni.showToast({
      title: '删除成功',
      icon: 'none',
      duration: 2000
    })
    init()
  })
}
const cancel = () => {
  state.deleteShow = false
  swipeRef.value[deleteIndex.value].closeAll()
}

const toggleOutPopup = (flag: boolean) => {
  showDefecate.value = flag
}

// 萧山医院上传图片功能
const isSign = ref(false)
const uploading = ref(false)
const selectPicInfo = ref({})

const getStatus = () => {
  let params = {
    empi: userInfo.value.empi,
    campaignCode: 'XS_WEIGHT_LOSS'
  }
  signStatus(params).then((res) => {
    isSign.value = res.data.isSign
  })
}
const setSignId = (item: any) => {
  selectPicInfo.value = item ? item : { campWieghtPics: [] }
}
// 选择图片
const selectFile = async (files: any) => {
  uploading.value = true
  const lists = [].concat(files.file)

  let fileListLen = selectPicInfo.value.campWieghtPics.length
  lists.map((item: any) => {
    selectPicInfo.value.campWieghtPics.push({
      ...item,
      status: 'uploading',
      message: '上传中'
    })
  })

  for (let i = 0; i < lists.length; i++) {
    const result: any = await uploadCamp(lists[i].url)
    const item = selectPicInfo.value.campWieghtPics[fileListLen]
    selectPicInfo.value.campWieghtPics.splice(fileListLen, 1, {
      ...item,
      status: 'success',
      message: '',
      url: result.data.relativePath,
      relativePath: result.data.relativePath
    })
    fileListLen++
  }
  uploading.value = false
}
// 图片列表获取
const getPicList = () => {
  let arr = selectPicInfo.value.campWieghtPics.map((val, idx) => {
    return {
      empi: userInfo.value.empi,
      sort: idx,
      picUrl: val.relativePath
    }
  })
  if (selectPicInfo.value.campWieghtPics.length == 0) {
    arr = [
      {
        empi: userInfo.value.empi,
        sort: 0,
        picUrl: null
      }
    ]
  }
  return arr
}
</script>

<style lang="scss" scoped>
.lists {
  box-sizing: border-box;
  height: 100vh;
  // padding: 24rpx 0;

  .scroll-Y {
    box-sizing: border-box;
    height: 100%;
  }
}
.wraps {
  height: calc(100vh - 600rpx);
  padding-bottom: 64rpx;

  .record-more {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 32rpx;
    margin-bottom: 24rpx;
    .record-title {
      font-weight: 700;
      font-size: 32rpx;
      color: #222222;
      display: flex;
      .line {
        width: 8rpx;
        height: 32rpx;
        border-radius: 0 4rpx 4rpx 0;
        background: #00d1b6;
        margin-right: 16rpx;
        transform: translateY(6rpx);
      }
    }
    .more {
      font-weight: 400;
      font-size: 28rpx;
      color: #666666;
      .img_more {
        width: 32rpx;
        height: 32rpx;
        font-size: 32rpx;
        // transform: translateY(6rpx);
        color: '#666666',
      }
    }
  }

  .content {
    width: calc(100% - 64rpx);
    // height: calc(100vh - 806rpx);
    // overflow: auto;
    padding-bottom: calc(184rpx + constant(safe-area-inset-bottom));
    padding-bottom: calc(184rpx + env(safe-area-inset-bottom));
    margin-left: 32rpx;

    ::v-deep .u-swipe-action-item {
      margin-bottom: 24rpx !important;
      border-radius: 12rpx !important;
      &:last-child {
        .min-water {
          border: none;
        }
      }
    }

    ::v-deep .u-swipe-action-item__right__button__wrapper {
      font-size: 24rpx;
      font-weight: 400;
      color: #fff;
      border-radius: 0 12rpx 12rpx 0 !important;
    }

    .card {
      .title {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 24rpx 0 8rpx;
        font-size: 30rpx;
        color: #222;
        margin-bottom: 20rpx;
        .drink-name {
          font-size: 32rpx;
          font-weight: 600;
          color: #222;
        }
      }
      .status {
        display: inline-block;
        padding: 2rpx 20rpx;
        margin-left: 20rpx;
        font-size: 24rpx;
        font-weight: 700;
        vertical-align: middle;
        border-radius: 4rpx;

        &.red {
          color: #ff503d;
          background: rgb(255 80 61 / 10%);
        }

        &.yellow {
          color: #ffd666;
          background: rgb(255 214 102 / 10%);
        }

        &.orange {
          color: #ff813c;
          background: rgb(255 129 60 / 10%);
        }

        &.green {
          color: #0cb67c;
          background: rgb(12 182 124 / 10%);
        }
      }

      .item {
        padding: 32rpx;
        font-size: 32rpx;
        color: #999;
        background: #fff;
        border-radius: 12rpx;

        &:nth-of-type(2) {
          margin-top: 0rpx;
        }

        .top {
          position: relative;
          display: flex;
          align-items: center;

          .name {
            display: inline-block;
            font-weight: 700;
            color: #222;
            vertical-align: middle;
          }

          .postprandial {
            display: inline-block;
            padding: 4rpx 20rpx;
            margin-left: 20rpx;
            font-size: 24rpx;
            color: #666;
            vertical-align: middle;
            background: #f5f5f5;
            border-radius: 20rpx 4rpx;
          }

          .time {
            position: absolute;
            top: 50%;
            right: 0;
            font-size: 14px;
            transform: translateY(-50%);
          }
        }

        .min {
          position: relative;
          min-height: 40rpx;
          margin-top: 32rpx;

          .name {
            display: flex;
            align-items: center;
            justify-content: space-between;

            .new-labels {
              display: flex;
              flex-direction: row;
              align-items: center;
              justify-content: space-between;
            }

            .label {
              font-size: 28rpx;
              font-weight: 400;
              color: #222;
            }

            .num {
              display: inline-block;
              font-size: 40rpx;
              font-weight: 700;
              color: #333;
              vertical-align: middle;
            }

            .unit {
              display: inline-block;
              margin-left: 20rpx;
              font-size: 28rpx;
              vertical-align: middle;
            }

            // &:nth-of-type(2) {
            //   margin-left: 20rpx;
            // }
          }

          .remark {
            position: absolute;
            top: 50%;
            right: 0;
            padding: 6rpx 30rpx;
            font-size: 24rpx;
            color: #00d1b6;
            border: 1px solid #00d1b6;
            border-radius: 24rpx;
            transform: translateY(-50%);
          }
        }

        .bottom {
          // padding-top: 20rpx;
          // margin-top: 32rpx;
          // font-size: 28rpx;
          // color: #222;
          // border-top: 1px solid #e5e6eb;

          .remark {
            display: inline-block;
            vertical-align: top;
          }

          .remarkContent {
            box-sizing: border-box;
            display: inline-block;
            width: calc(100% - 46px);
            font-weight: 400;
            color: #666;
            word-wrap: break-word;
            vertical-align: top;
          }
        }
      }
    }

    .nodate {
      text-align: center;
      padding-top: 240rpx;
      .img {
        display: inline-block;
        width: 320rpx;
        height: 240rpx;
      }

      .nodate_text {
        .name {
          display: block;
          margin-top: 10rpx;
          font-size: 28rpx;
          color: #666;
          text-align: center;
        }
      }
    }
  }
}
::v-deep .u-popup {
  .u-popup__content {
    overflow: hidden;

    .abnormalContent {
      width: 80vw;

      .title {
        padding: 40rpx 32rpx 0;
        font-size: 34rpx;
        font-weight: 700;
        color: #1d2129;
        text-align: center;
      }

      .content {
        display: block;
        padding: 15rpx 32rpx 40rpx;
        font-size: 30rpx;
        color: #4e5969;
        text-align: center;
        border-bottom: 2rpx solid #e5e6eb;
      }

      .know {
        height: 88rpx;
        font-size: 32rpx;
        line-height: 88rpx;
        color: #00d1b6;
        text-align: center;
      }
    }
  }

  .popup-wrap {
    padding-bottom: calc(160rpx + constant(safe-area-inset-bottom));
    padding-bottom: calc(160rpx + env(safe-area-inset-bottom));

    .title {
      padding: 32rpx;
      font-size: 32rpx;
      font-weight: 700;
      text-align: center;
      border-bottom: 1rpx solid #e5e6eb;
    }

    .popupContent {
      padding: 32rpx;
      font-size: 30rpx;
      color: #222;
    }
    .scroll-slide {
      max-height: 800rpx;
    }

    .tabKey {
      position: relative;
      padding: 20rpx 30rpx 30rpx;

      .name {
        font-size: 30rpx;
        font-weight: 700;
        color: #00d1b6;

        &.on {
          color: #fff;
        }
      }

      .keyboard {
        position: absolute;
        top: 50%;
        right: 30rpx;
        transform: translateY(-50%);

        .img {
          display: inline-block;
          font-size: 36rpx;
          color: #999;
          vertical-align: middle;
          width: 36rpx;
          height: 36rpx;
        }

        .key {
          display: inline-block;
          margin-left: 10rpx;
          font-size: 28rpx;
          color: #222;
          vertical-align: middle;
        }
      }
    }

    .listWraps {
      width: calc(100% - 32rpx);
      height: 118rpx;
      margin: 32rpx 0rpx 0 32rpx;
      // display: flex;
      // flex-direction: row;
      // align-items: center;
      // justify-content: space-between;

      .scroll-view_H {
        width: 100%;
        white-space: nowrap;
      }

      .item {
        display: inline-block;
        // display: flex;
        width: 112rpx;
        height: 110rpx;
        margin-right: 16rpx;
        text-align: center;
        background: #fafafa;
        border-radius: 12rpx;

        // &:nth-last-child(1) {
        //   margin-right: 0;
        // }

        .name {
          display: block;
          width: 100%;
          margin: 10rpx 0 8rpx;
          font-size: 28rpx;
          font-weight: 600;
          color: #333;
          text-align: center;

          // &:nth-child(1) {
          //   display: block;
          //   font-size: 20rpx;
          //   font-weight: 700;
          //   color: #333;
          // }
        }

        .time-title {
          display: block;
          width: 100%;
          font-size: 26rpx;
          font-weight: 400;
          color: #666;
          text-align: center;
        }

        &.on {
          background: #00d1b6;

          .name {
            color: #fff;
          }

          .time-title {
            color: #fff;
          }

          // &::after {
          //   position: absolute;
          //   bottom: -8rpx;
          //   left: 50%;
          //   width: 0;
          //   height: 0;
          //   content: '';
          //   border-top: 10rpx solid #00d1b6;
          //   border-right: 10rpx solid transparent;
          //   border-left: 10rpx solid transparent;
          //   transform: translateX(-50%);
          // }
        }
      }
    }

    .btn {
      height: 88rpx;
      margin: 0 32rpx;
      font-size: 32rpx;
      font-weight: 700;
      line-height: 88rpx;
      color: #fff;
      text-align: center;
      background: #00d1b6;
      border-radius: 44rpx;
    }

    .fixedBtn {
      position: fixed;
      bottom: 0;
      left: 0;
      width: 100%;
      padding: 24rpx 0;
      padding-bottom: calc(24rpx + constant(safe-area-inset-bottom));
      padding-bottom: calc(24rpx + env(safe-area-inset-bottom));
      color: #fff;
      text-align: center;
      background: #fff;
      border-top: 1rpx solid #e5e6eb;

      .name {
        display: inline-block;
        width: calc(100% - 60rpx);
        padding: 22rpx 0;
        margin: 0 30rpx;
        font-size: 32rpx;
        background: #00d1b6;
        border-radius: 50rpx;
      }
    }

    .measure {
      display: inline-block;
      width: 100%;
      padding-bottom: 30rpx;
      background: #fff;

      .numWrap {
        display: flex;
        flex-flow: row wrap;
        align-items: center;
        justify-content: center;
        // grid-template-columns: repeat(2, 1fr);
        margin: 20rpx 30rpx 0;
        background: #fafafa;
        border-radius: 4rpx;

        .item {
          display: inline-block;
          // width: 33.3%;
          height: 200rpx;
          padding: 10rpx 0 0rpx;
          margin: 0;
          vertical-align: middle;

          .value {
            display: block;
            width: 100%;
            padding: 20rpx 0 8rpx;
            font-size: 48rpx;
            color: #00d1b6;
            text-align: center;
            background: #fafafa;
            border: 0;
          }

          .wraps {
            padding: 10rpx 0;
            margin: 0 20rpx;
            font-size: 30rpx;
            color: #00d1b6;
            text-align: center;
            border-top: 1rpx solid #00d1b6;

            .name {
              display: inline-block;
              vertical-align: middle;

              &:nth-child(1) {
                margin-right: 8rpx;
              }
            }
          }
        }
      }
    }

    .measureTime {
      position: relative;
      display: flex;
      justify-content: space-between;
      padding: 32rpx 0;
      margin: 0 32rpx;

      .name {
        font-size: 30rpx;
        font-weight: 700;
        color: #222;
      }

      .time {
        min-width: 200rpx;
        font-size: 30rpx;
        font-weight: 400;
        color: #222;
        text-align: right;

        .titles {
          display: inline-block;
          vertical-align: middle;
        }

        .img {
          display: inline-block;
          width: 30rpx;
          height: 30rpx;
          vertical-align: middle;
        }
      }
    }

    .sleepTime {
      padding: 32rpx;
      margin-bottom: 24rpx;
      background: #fafafa;
      border: 1rpx solid #e5e6eb;
      border-radius: 16rpx;
    }

    .measureDetail {
      margin: 0 32rpx;
      font-size: 26rpx;
      color: #999;

      .item {
        display: block;

        &:nth-child(2) {
          margin-top: 10rpx;
        }
      }
    }

    .content {
      position: relative;

      .contentWrap {
        margin: 0 32rpx;

        .contentItem {
          margin-top: 32rpx;
          font-size: 32rpx;
          color: #222;
        }

        .img {
          display: block;
          width: 100%;
          height: auto;
          margin-top: 30rpx;
        }
      }

      .fixedBtn {
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100%;
        padding: 24rpx 0;
        padding-bottom: calc(24rpx + constant(safe-area-inset-bottom));
        padding-bottom: calc(24rpx + env(safe-area-inset-bottom));
        color: #fff;
        text-align: center;
        background: #fff;
        border-top: 1rpx solid #fff;

        p {
          padding: 22rpx 0;
          margin: 0 30rpx;
          font-size: 32rpx;
          background: #02bcc3;
          border-radius: 50rpx;
        }
      }
    }
  }

  .u-popup__content__close {
    top: 40rpx;

    .uicon-close {
      font-size: 32rpx !important;
      line-height: 32rpx !important;
    }
  }
}

::v-deep
  .u-popup
  .u-slide-up-enter-to
  .u-picker
  .u-picker__view__column
  .u-picker__view__column__item {
  line-height: 34px !important;
}

::v-deep .u-popup .u-slide-up-enter-active {
  overflow: hidden;
  border-top-left-radius: 32rpx !important;
  border-top-right-radius: 32rpx !important;

  .u-toolbar {
    .u-toolbar__wrapper__confirm {
      color: #00d1b6 !important;
    }
  }
}

::v-deep .u-popup .u-slide-up-enter-to .u-picker .u-picker__view {
  height: 400px !important;
}

::v-deep .u-safe-area-inset-bottom {
  padding-bottom: 0 !important;
}
.fixed {
  position: fixed;
  width: 100%;
  bottom: 0;
  left: 0;
  z-index: 10;
  padding: 24rpx 32rpx;
  padding-bottom: calc(24rpx + constant(safe-area-inset-bottom));
  padding-bottom: calc(24rpx + env(safe-area-inset-bottom));
  box-sizing: border-box;
  background: #ffffff;
  display: flex;
  gap: 24rpx;
  .cancel_btn {
    width: 49%;
    height: 88rpx;
    line-height: 88rpx;
    background: #ffffff;
    border-radius: 44rpx;
    font-weight: 500;
    font-size: 32rpx;
    color: #666666;
    border: 1rpx solid #e5e6eb;
  }
  .confirm_btn {
    width: 49%;
    height: 88rpx;
    line-height: 88rpx;
    background: #00d1b6;
    border-radius: 44rpx;
    font-weight: 500;
    font-size: 32rpx;
    color: #ffffff;
  }
}

.food-type {
  display: inline-block;
  padding: 4rpx 20rpx 2rpx;
  margin-left: 16rpx;
  font-size: 24rpx;
  font-weight: 400;
  color: #666;
  background: #f5f5f5;
  border-radius: 20rpx 4rpx;
}

.source {
  font-size: 26rpx;
  color: #999;
}
</style>
